home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- # Change the above to point to your site's perl installation.
- #
- # gmailbatch -- script to aid in batch submissions to gmail
- #
- #
- # usage: gmailbatch destination < inputfile
- #
- # where "destination" is the email alias of a gmail server
- #
- # "inputfile" is a collection of messages to be sent to gmail,
- # separated by lines beginning with "%%". The remainder of a
- # "%%" line is taken to be the subject of the following message.
- # If the remainder of the "%%" line is blank, then the first
- # line of the message is also used as the subject.
- #
- # Examples:
- #
- # gmailbatch cwis@foobar.edu <<EOF
- # %%About apples and oranges
- # This directory contains information on apples and oranges.
- # %%Apples
- # Apples are red or green on the outside and white on the inside.
- # Johnny Appleseed used to plant them.
- # %%
- # Oranges
- #
- # Oranges are orange on the outside and divided into sections on the
- # inside. Anita Bryant used to sing about them.
- # EOF
- #
- #
- # gmailbatch events@foobar.edu <<EOF
- # %%1993-03-17 St. Patrick's Day at the Coffeehouse
- # Drink green near-beer and sing along with Toby O'Brien at the
- # Coffeehouse, 8:00 p.m.
- # %%1993-07-04 Independence Day fireworks at Town Lake
- # Fireworks for the whole family on the lake. Sponsored by the
- # Volunteer Fire Brigade.
- # EOF
- #
- #
- #-------------------------------------------------------------------------
- #
- # Author: Prentiss Riddle (riddle@rice.edu).
- #
- # History:
- # 02/15/93 PASR Original version based on smug 0.1.
- #
- #-------------------------------------------------------------------------
-
- $separator = '%%';
- $sendmail = "/usr/lib/sendmail";
- $usage = "usage: gmailbatch destination\n";
-
- unless ($#ARGV == 0) {
- print STDERR "$usage";
- exit(1);
- }
- $mailto = $ARGV[0];
- print "Mailing the following items to $mailto:\n";
-
- $error = 0;
- $skip = 1;
- MAINLOOP:
- while (<STDIN>) {
- chop;
- if (/^$separator/) {
- close (CURFILE) unless $skip;
- s/^$separator//;
- if ($_ eq "") {
- # no title -- cannibalize first line of text block
- $_ = <STDIN>; # don't chop yet!
- if (/^$separator/) {
- # uh-oh -- null text block
- print "Error: missing title in $dir\n";
- $error = 1;
- redo MAINLOOP;
- }
- chop;
- }
- open (CURFILE, "| $sendmail $mailto") ||
- die("Couldn't open pipe to $sendmail: $!");
- $skip = 0;
- print CURFILE "Subject: $_\n\n";
- print "$_\n";
- } else {
- print CURFILE $_, "\n" unless $skip;
- }
-
- } # end MAINLOOP
- close (CURFILE) unless $skip;
-
- exit $error;
-
- #------------------------------------------------------------------------
-
- # end of gmailbatch script
-